package com.gxa.p2p.controller;
import com.gxa.p2p.common.JsonResult;
import com.gxa.p2p.pojo.Agreement;
import com.gxa.p2p.pojo.Article;
import com.gxa.p2p.pojo.Feedback;
import com.gxa.p2p.pojo.Management;
import com.gxa.p2p.service.FeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 邓邦武
 * @author HS
 */
@CrossOrigin
@RestController
@RequestMapping("/feedback")
@Api(value = "意见处理操作接口")

public class FeedbackController {
    @Autowired
    private FeedbackService service=null;

    /**
     * 邓邦武
     */
    @PostMapping("/findFeedbackById")
    @ApiOperation(value = "意见的编号查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "编号",required = true)
    })
    public Map findFeedbackById(@RequestParam Long id){

        Feedback feedback = service.findFeedbackById(id);

        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("成功");
        jsonResult.setData(feedback);
        return jsonResult.getDataMap();
    }
    /**
     * 邓邦武
     * @param map
     * @return
     */
    @PostMapping("/findFeedbackByPage")
    @ApiOperation(value = "意见的分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name="advice",value = "问题关键字",required = false),
            @ApiImplicitParam(name="state",value = "状态",required = false),
            @ApiImplicitParam(name="page",value = "页码",required = true),
            @ApiImplicitParam(name="size",value = "每页记录数",required = true)
    })
    public Map findFeedbackByPage(@RequestBody Map map){

        Map<Integer, List<Feedback>> resultMap = service.findFeedbackByPage(map);

        Set<Integer> set = resultMap.keySet();
        Integer count=0;
        for (Integer integer : set) {
            count=integer;
        }
        List<Feedback> list = resultMap.get(count);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("成功");
        jsonResult.setData(list);
        jsonResult.getDataMap().put("count",count);
        return jsonResult.getDataMap();

    }

    /**
     * 邓邦武
     * @param map
     * @return
     */
    @PostMapping("/updateFeedback")
    @ApiOperation(value = "处理意见")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "意见编号",required = true),
            @ApiImplicitParam(name = "reply",value = "回复",required = true),
            @ApiImplicitParam(name = "state",value = "状态",required = true)

    })
    public Map updateFeedback(@RequestBody Map map){


        service.updateFeedback(map);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("成功");
        return jsonResult.getDataMap();
    }

}
